//
//  CShareCommentDelMgr.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/3/10.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "CShareCommentDelMgr.h"
#import "EFengShareCommentDel.h"

@implementation CShareCommentDelMgr

- (BOOL)insertCommentDelWithCommentDel:(EFengShareCommentDel *)commentDel
{
    __block BOOL ret = NO;
    
    [[FMShareDataBase shareDataBase].shareQueue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        ret = [db executeUpdate:@"INSERT INTO EFENGSHARECOMMENTDEL(commentId, date, type,yuLiuZiduan1,yuLiuZiduan2,yuLiuZiduan3) VALUES (?, ?, ?, ?, ?, ?)",M_STOREVALUE(commentDel.commentId), M_STOREVALUE(commentDel.date),M_STOREVALUE(commentDel.type),M_STOREVALUE(commentDel.yuLiuZiduan1),@(commentDel.yuLiuZiduan2),M_STOREVALUE(commentDel.yuLiuZiduan3)];
        
    }];
    return ret;

}

- (BOOL)batchInsertCommentDelWithDelList:(NSArray *)delList
{
    if(delList == nil && [delList count] <= 0)
    {
        return NO;
    }
    //     FMDatabaseQueue *queen = [FMDatabaseQueue  databaseQueueWithPath:[[CFolderMgr shareInstance] companyCommonDatabasePath]];
    __block BOOL ret = NO;
    
    [[FMShareDataBase shareDataBase].shareQueue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        for(EFengShareCommentDel *comment in delList)
        {
            if (!M_ISSTRNULL(comment.commentId)) {
                ret = [db executeUpdate:@"INSERT INTO EFENGSHARECOMMENTDEL(commentId, date, type) VALUES (?, ?, ?)",M_STOREVALUE(comment.commentId), M_STOREVALUE(comment.date),M_STOREVALUE(comment.type)];
                
                if(!ret)
                {
                    *rollback = YES;
                }
                
            }
        }
        
    }];
    return ret;

}

- (NSString *)getMaxDateCommentDel
{
    {
        __block NSString *result = nil;
        [[FMShareDataBase shareDataBase].shareQueue inDatabase:^(FMDatabase *db) {
            result = [db stringForQuery:@"select max(date) from EFENGSHARECOMMENTDEL"];
        }];
        return result;
    }

}

@end
